<?php
/*
 * @Descripttion: 
 * @version: 
 * @Author: ewgof
 * @Date: 2020-09-24 21:37:53
 * @LastEditors: ewgof
 * @LastEditTime: 2020-10-25 16:57:14
 */
namespace app\http\controller\admin;


class WebsiteConfig extends Base
{
    public function info($request)
    {
        $info = $this->db->get('website_config', ['id', 'key_words', 'favicon', 'logo', 'user_upload_size', 'user_upload_number', 'guest_upload_size', 'guest_upload_number']);
        return api_json_return(0, '', $info);
    }


    public function set($request)
    {
        $opts = $request->post();
        if (empty($opts['id'])) {
            return api_json_return(2);
        }
        $id = $opts['id'];
        unset($opts['id']);
        
        if (!empty($opts['key_words'])) {
            $opts['key_words'] = \str_replace('，', ',', $opts['key_words']);
        }

        $info = $this->db->update('website_config', $opts, ['id' => $id])->rowCount();
        if ($info === 1) {
            $website_config = $db->get('website_config', ['key_words', 'description', 'favicon', 'logo', 'user_upload_size', 'user_upload_number', 'guest_upload_size', 'guest_upload_number']);
            \cw\facade\Cache::set('website_config', $website_config);
            return api_json_return(0);
        } elseif ($info === 0) {
            return api_json_return(18);
        } else {
            return api_json_return(1);
        }
    }
}